var express = require('express');
var router = express.Router();
let db=require('../sql');

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index');
});

router.post('/main', function(req, res, next) {
  // res.end('1111');
//  获取用户输入的内容
  console.log(req.body);
  let value=req.body;
  let user_name=value.user_name;
  let user_pwd=value.user_pwd;
//  查询数据库
  db.query('select * from admin where admin_name=? and admin_pwd=?',[user_name,user_pwd],function (err,data){
    if(err){
      throw err;
    }else if(data.length>0){
      res.render('main');
    }else{
      res.end('用户名或者密码有误~~~');
    }
  })
});

module.exports = router;
